package gsw.demo.router.toolrouter;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import gsw.demo.router.R;
import gsw.tool.router.annotation.Extra;
import gsw.tool.router.annotation.Route;
import gsw.tool.router.core.ToolRouter;
import gsw.tool.router.core.template.TestService;

// 在支持路由的页面上添加注解(必选)
// 这里的路径需要注意的是至少需要有两级，/xx/xx
@Route(path = "/demo1/activityToolRouterDemo1")
public class ActivityToolRouterDemo1 extends AppCompatActivity {

    //给IService接口设置Extra注解,用来向其他路由页面传递IService对象
    @Extra(name = "/main/service1")
    TestService testService1;
    @Extra(name = "/main2/service2")
    TestService testService2;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toolrouter_demo1);
        init();
        initExtra();
    }

    private void init() {
        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.jump_demo1_demo2) {
                    // 应用内带参数的跳转(通过URL跳转在'进阶用法'中)
                    ToolRouter.getInstance().build("/demo1/activityToolRouterDemo2")
                            .withLong("key1", 666L)
                            .withString("key2", "888")
                            .navigation();
                } else if (v.getId() == R.id.jump_demo2_demo1) {
                    //应用外的简单跳转
                    ToolRouter.getInstance().build("/demo2/activityToolRouter2Demo1").navigation();
                }
            }
        };
        findViewById(R.id.jump_demo1_demo2).setOnClickListener(clickListener);
        findViewById(R.id.jump_demo2_demo1).setOnClickListener(clickListener);
    }

    /**
     * 处理Extra注解
     */
    private void initExtra() {
        //用来处理Extra注解
        ToolRouter.getInstance().inject(this);
        //用来处理Extra注解
        testService1.test(this);
        testService2.test(this);
    }
}
